package com.neuedu.studentmanage.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.studentmanage.entity.Report;
import com.neuedu.studentmanage.entity.Classroom;
import com.neuedu.studentmanage.entity.Pager;
import com.neuedu.studentmanage.entity.Result;
import com.neuedu.studentmanage.service.ReportService;
@Controller
public class ReportController {
	@Autowired
	private ReportService reportService;
	private Logger logger=Logger.getLogger(ReportController.class);
	

	@RequestMapping("admin/report")
	public String reportIndex() {
		logger.info("admin/report");
		// 首页只打开页面，不加载数据;页面的数据使用在easy ui中通过ajax技术进行异步加载的
		return "admin/reportlist";
	}

	// easyui请求时使用的是post方法，这里需要使用post方法
	// easy ui进行分页查询时，使用page传递查询的页码，使用rows传递查询的记录数
	@RequestMapping("admin/reportlist")
	@ResponseBody
	public Pager<Report> reportList(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer rows) {
		Pager<Report> pager = new Pager<>(page, rows);
		// 根据查询条件进行分页查询
		List<Report> reportList = reportService.findListByPager(pager);
		Integer total = reportService.findTotalByPager(pager);

		// 把查询到数据保存到pager对象中，再转换成json返回给easy ui
		pager.setRows(reportList);
		pager.setTotal(total);

		return pager;
	}

	@RequestMapping("admin/reportadd")
	@ResponseBody
	public Result doAdd(Report report) {
		
		


		Result result = reportService.add(report);

		return result;
	}

	@RequestMapping("admin/reportedit")
	@ResponseBody
	public Result doEdit(Report report) {
		Result result = reportService.edit(report);
		return result;
	}

	@RequestMapping("admin/reportdelete")
	@ResponseBody
	public Result doDelete(Integer repId) {

		List<Report> list = new ArrayList<Report>();
		list.add(new Report(repId));
		Result result = reportService.deleteByIds(list);
		return result;
	}
	@RequestMapping("admin/reportlistall")
	@ResponseBody
	public List<Report> listCategories() {
		return reportService.findAll();
	}

}
